package com.zeedev.flyingsaucer.beers.activities.login;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.widget.SimpleCursorAdapter;
import com.google.inject.Provides;
import com.google.inject.ProvisionException;
import com.google.inject.name.Named;
import com.zeedev.flyingsaucer.beers.activities.storechooser.StoreSpinner;
import com.zeedev.flyingsaucer.modules.StoreModule.interfaces.Store;
import mobi.zeedev.flyingsaucer.common.DataModule.FlyingSaucerConv;
import mobi.zeedev.flyingsaucer.common.DataModule.Util;
import roboguice.config.AbstractAndroidModule;

//import mobi.zeedev.flyingsaucer.scala.delegates.AutoPreferenceCredentials;

/**
 * User: James
 * Date: 12/27/10
 * Time: 10:15 PM
 */
public class LoginModule extends AbstractAndroidModule {

    @Override
    protected void configure() {

//        bind(AutoPreferenceCredentials.class).asEagerSingleton();



    }

    @Provides
    @Named("childOfLoginActivity")
    StoreSpinner provideParentStoreSpinner(Context mContext) {
        if (mContext.getClass() == LoginActivity.class) {
            return ((LoginActivity) mContext).getStoreSpinner();
        }
        else {
            throw new ProvisionException("Could not cast mContext into login activity for storespinner / store downloader.");
        }
    }


/*    @Provides
    ArrayAdapter<String> providesStoreListAdapter(Context mContext, Store storesModel) {
        HashMap<String, String> storeMap = storesModel.getNameIdStoreMap();

        List<String> storeNames = new ArrayList<String>();
        for (String curStoreName : storeMap.keySet()) {
            storeNames.add(curStoreName);
        }
        ArrayAdapter<String> aa = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, storeNames);
        aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        aa.sort(new Comparator<String>() {
            @Override
            public int compare(String object1, String object2) {
                return object1.compareTo(object2);
            }
        });

        return aa;
    }*/

    @Provides
    SimpleCursorAdapter provideStoreListSpinnerAdapter(Activity mActivity, Store stores) {
        Cursor mCursor = mActivity.managedQuery(FlyingSaucerConv.Stores.CONTENT_URI, Util.asAr(FlyingSaucerConv.Stores.STORES_KEY + " as " + FlyingSaucerConv.Stores._ID, FlyingSaucerConv.Stores.NAME, FlyingSaucerConv.Stores.NUMBER), null, null, null);
        SimpleCursorAdapter sca = new SimpleCursorAdapter(mActivity, android.R.layout.simple_spinner_item, mCursor, Util.asAr(FlyingSaucerConv.Stores.NAME), Util.asIntArray(android.R.id.text1));

        sca.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        return sca;
    }


}
